package com.ruoyi.web.controller.bussiness;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.entity.po.TPlayerLiveData;
import com.ruoyi.service.IPlayerLiveDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;

/**
 * 活动数据-直播(t_player_live_data)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/playerLiveData")
@Api(tags = "PC-12.直播数据")
public class TPlayerLiveDataController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private IPlayerLiveDataService playerLiveDataService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TPlayerLiveData selectOne(Integer id) {
        return playerLiveDataService.selectByPrimaryKey(id);
    }

    /**
     * 分页查询
     */
    @GetMapping("/list")
    @ApiOperation("查询选手直播数据")
    public TableDataInfo list(Integer playerId) {
        startPage();
        return getDataTable(playerLiveDataService.selectList(playerId));
    }

    @Valid
    @Log(title = "添加选手直播数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation("新增选手直播数据")
    public AjaxResult add(@Valid @RequestBody TPlayerLiveData playerLiveData) {
        return toAjax(playerLiveDataService.insertSelective(playerLiveData));
    }

    @Valid
    @Log(title = "编辑选手直播数据", businessType = BusinessType.INSERT)
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation("编辑选手直播数据")
    public AjaxResult edit(@Valid @RequestBody TPlayerLiveData playerLiveData) {
        return toAjax(playerLiveDataService.updateByPrimaryKeySelective(playerLiveData));
    }

    @Log(title = "删除选手直播数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    @ApiOperation("删除选手直播数据")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult remove(String ids) {
        for (var id : Convert.toIntArray(ids)) {
            playerLiveDataService.deleteByPrimaryKey(id);
        }
        return toAjax(true);
    }

    

}
